
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;

public class Personagem extends Inter {
	private int dx, dy;
	private static String loc = "res\\crianca59.gif";
	private List<Tiro> misseis;
	
	public Personagem(){
		super(100,100,loc);
		misseis = new ArrayList<Tiro>();
	}
	public List<Tiro> getMisseis() {
		return misseis;
	}
	public void mexer(){
		//System.out.println(x +"," + y);
		x+=dx;// 0 e 1073
		y+=dy;//-4 a 568
		if(this.x<0){
			x =0;
		}
		if(this.x>1073){
			x =1073;
		}
		if(this.y<-4){
			y =-4;
		}
		if(this.y>568){
			y =568;
		}
	}
	 public static void music2(){ 
	        try	{
	        	
	        	//if(c==1){
	        	AudioInputStream audio = AudioSystem.getAudioInputStream(new File ("res\\Punch.wav"));
	        	Clip clip = AudioSystem.getClip();
	        	clip.open(audio);
	        	clip.start();
	        	
	        }
	        catch(UnsupportedAudioFileException uae) {
	            System.out.println(uae);
	        }
	        catch(IOException ioe) {
	            System.out.println(ioe);
	        }
	        catch(LineUnavailableException lua) {
	            System.out.println(lua);
	        }
	    }

	public void atira(){
		this.misseis.add(new Tiro(x+largura, y+altura/2));
	}
	
	public void keyPressed(KeyEvent tecla){
	int codigo = tecla.getKeyCode();
	if(codigo == KeyEvent.VK_SPACE)
	{
		atira();
		music2();
	}
	if (codigo == KeyEvent.VK_UP){
	dy = -1;
	                              }
	if (codigo == KeyEvent.VK_DOWN){
	dy = 1;
	                                 }
	if (codigo == KeyEvent.VK_LEFT){
		dx = -1;
		                              }
		if (codigo == KeyEvent.VK_RIGHT){
		dx = 1;
		                                 }
			
	                                         }
	public void keyReleased(KeyEvent tecla){
		int codigo = tecla.getKeyCode();
		
		if (codigo == KeyEvent.VK_UP){
			dy = 0;
			                              }
		if (codigo == KeyEvent.VK_DOWN){
			dy = 0;
			                                 }
			if (codigo == KeyEvent.VK_LEFT){
				dx = 0;
				                              }
				if (codigo == KeyEvent.VK_RIGHT){
				dx = 0;
				                                 }
		
		
	}
	
}


